package pl.koziolekweb.jqr.ui;

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

public class ControlWidget extends JPanel {

	private static final long serialVersionUID = 1L;
	private TextProcessor textProcessor;
	private JButton start;
	private JButton stop;

	public ControlWidget(TextProcessor textProcessor) {
		this.textProcessor = textProcessor;
		setBorder(LineBorder.createBlackLineBorder());
		setPreferredSize(new Dimension(790, 45));
		start = new JButton("Start");
		stop = new JButton("Stop");  
		addListener();
		add(start);
		add(stop);
	}

	private void addListener() {
		start.addMouseListener(new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent e) {
				textProcessor.start();
			}
		});
		stop.addMouseListener(new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent e) {
				textProcessor.stop();
			}
		});

	}

	public void setTextProcessor(TextProcessor textProcessor) {
		this.textProcessor = textProcessor;
	}
}
